package Thread;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-08-09
 * Time: 20:57
 */
public class demo30 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        //参数1表示要完成什么事,第二个参数表示完成这件事所用时间
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("Hello3");
            }
        }, 3000);

        //timer不仅能安排一个任务
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("Hello2");
            }
        }, 2000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("Hello1");
            }
        }, 1000);
        System.out.println("程序开始运行");
    }
}
